package com.jeesite.modules.home.service;

import java.util.Date;
import java.util.List;

import com.jeesite.modules.msg.entity.content.PcMsgContent;
import com.jeesite.modules.msg.utils.MsgPushUtils;
import com.jeesite.modules.sys.utils.UserUtils;
import com.jeesite.modules.task.deploy.entity.DcSupTaskInfo;
import com.jeesite.modules.task.deploy.service.DcSupTaskInfoService;
import com.jeesite.modules.yzw.entity.MsgDetail;
import com.jeesite.modules.yzw.service.LehandYzwPushTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeesite.common.entity.Page;
import com.jeesite.common.service.CrudService;
import com.jeesite.modules.home.entity.DcSupTaskActionExplain;
import com.jeesite.modules.home.dao.DcSupTaskActionExplainDao;

/**
 * 任务部署分发表-牵头领导批示Service
 * @author xhc
 * @version 2022-03-28
 */
@Service
@Transactional(readOnly=false)
public class DcSupTaskActionExplainService extends CrudService<DcSupTaskActionExplainDao, DcSupTaskActionExplain> {


	@Autowired
	private LehandYzwPushTask lehandYzwPushTask;
	/**
	 * 获取单条数据
	 * @param dcSupTaskActionExplain
	 * @return
	 */
	@Override
	public DcSupTaskActionExplain get(DcSupTaskActionExplain dcSupTaskActionExplain) {
		return super.get(dcSupTaskActionExplain);
	}
	
	/**
	 * 查询分页数据
	 * @param dcSupTaskActionExplain 查询条件
	 * @return
	 */
	@Override
	public Page<DcSupTaskActionExplain> findPage(DcSupTaskActionExplain dcSupTaskActionExplain) {
		return super.findPage(dcSupTaskActionExplain);
	}
	
	/**
	 * 查询列表数据
	 * @param dcSupTaskActionExplain
	 * @return
	 */
	@Override
	public List<DcSupTaskActionExplain> findList(DcSupTaskActionExplain dcSupTaskActionExplain) {
		return super.findList(dcSupTaskActionExplain);
	}
	
	/**
	 * 保存数据（插入或更新）
	 * @param dcSupTaskActionExplain
	 */
	@Override
	@Transactional(readOnly=false)
	public void save(DcSupTaskActionExplain dcSupTaskActionExplain) {
		dcSupTaskActionExplain.setExplainName(UserUtils.get(dcSupTaskActionExplain.getExplainCode()).getUserName());
		dcSupTaskActionExplain.setExplainTime(new Date());
//		DcSupTaskActionExplain dcSupTaskActionExplaindb =new  DcSupTaskActionExplain();
//		dcSupTaskActionExplaindb.setExplainCode(dcSupTaskActionExplain.getExplainCode());
//		dcSupTaskActionExplaindb.setActionId(dcSupTaskActionExplain.getActionId());
//		DcSupTaskActionExplain dcSupTaskActionExplain1 = dao.getByEntity(dcSupTaskActionExplaindb);
//		if(dcSupTaskActionExplain1!=null &&dcSupTaskActionExplain.getExplainCode()!=null){
//			return;
//		}
		super.save(dcSupTaskActionExplain);
		//1加市领导批示，消息提醒给任务发布人
		DcSupTaskInfo dcSupTaskInfo = dao.getInfo(dcSupTaskActionExplain.getActionId());
		PcMsgContent msg = new PcMsgContent();
		msg.setTitle("提示信息");
		msg.setContent("您有一个任务:\""+dcSupTaskInfo.getTaskTitle()+"\"已批示,请及时查看");
		MsgPushUtils.push(msg, dcSupTaskInfo.getId(), "pishitofaburen", dcSupTaskInfo.getCreateBy());
		//发送易政网消息
		MsgDetail msgDetail = new MsgDetail();
		msgDetail.setSendid(UserUtils.getUser().getUserCode());
		msgDetail.setSubjectid(dcSupTaskInfo.getCreateBy());
//		msgDetail.setMesg("您有一个任务:\""+dcSupTaskInfo.getTaskTitle()+"\"已批示,请及时查看");
//		lehandYzwPushTask.pushYzwMsg(msgDetail);
		msgDetail.setMesg("您有一个任务:\""+dcSupTaskInfo.getTaskTitle()+"\"已批示,请及时登录系统查看");
		lehandYzwPushTask.pushYzwShortMsg(msgDetail);
	}
	
	/**
	 * 更新状态
	 * @param dcSupTaskActionExplain
	 */
	@Override
	@Transactional(readOnly=false)
	public void updateStatus(DcSupTaskActionExplain dcSupTaskActionExplain) {
		super.updateStatus(dcSupTaskActionExplain);
	}
	
	/**
	 * 删除数据
	 * @param dcSupTaskActionExplain
	 */
	@Override
	@Transactional(readOnly=false)
	public void delete(DcSupTaskActionExplain dcSupTaskActionExplain) {
		super.delete(dcSupTaskActionExplain);
	}
	
}